package com.bea.ftd.dashboard.service;

import java.util.Calendar;
import java.util.Optional;

import org.springframework.data.repository.CrudRepository;

import com.bea.ftd.common.intf.IGatewayEntity;

public interface IGatewayService {

	/**
	 * 设置创建或更新时间
	 * 
	 * @param gatewayEntity
	 * @param repository
	 */
	default void setCreateOrUpdateTime(IGatewayEntity gatewayEntity,
			CrudRepository<? extends IGatewayEntity, Long> repository) {
		if (null == gatewayEntity.getId()) {
			gatewayEntity.setCreateTime(Calendar.getInstance().getTime());
		} else {
			Optional<? extends IGatewayEntity> opt = repository.findById(gatewayEntity.getId());
			if (opt.isPresent()) {
				gatewayEntity.setCreateTime(opt.get().getCreateTime());
			}
		}
		gatewayEntity.setUpdateTime(Calendar.getInstance().getTime());
	};
}
